package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.sc.nft.dao.*;
import com.sc.nft.entity.*;
import com.sc.nft.entity.vo.IncomeRecordPageVO;
import com.sc.nft.entity.vo.MerchantPledgeTaskCycleRewardsDetailsVO;
import com.sc.nft.entity.vo.merchantPledgeTask.*;
import com.sc.nft.enums.MerchantPledgeTaskExamineStatusEnum;
import com.sc.nft.enums.PledgeTaskTypeEnum;
import com.sc.nft.enums.UserCollectionFreezingStatusEnum;
import com.sc.nft.enums.UserMerchantPledgeTaskStatusEnum;
import com.sc.nft.exception.GlobalRunTimeException;
import com.sc.nft.service.UserCollectionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.service.MerchantPledgeTaskConfService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 商户质押任务配置主表服务接口实现
 *
 * @author Sun
 * @since 2023-08-21 15:29:13
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class MerchantPledgeTaskConfServiceImpl implements MerchantPledgeTaskConfService {

    private final MerchantPledgeTaskConfDao merchantPledgeTaskConfDao;
    private final MerchantPledgeTaskCycleConfDao merchantPledgeTaskCycleConfDao;
    private final MerchantPledgeTaskRewardsConfDao merchantPledgeTaskRewardsConfDao;
    private final UserMerchantPledgeTaskRecordsDao userMerchantPledgeTaskRecordsDao;
    private final MerchantPledgeTaskIncomeConfDao merchantPledgeTaskIncomeConfDao;
    private final MerchantPledgeTaskSettlementRewardsLogDao merchantPledgeTaskSettlementRewardsLogDao;
    private final UserMerchantPledgeTaskDetailsRecordsDao userMerchantPledgeTaskDetailsRecordsDao;
    private final UserCollectionDao userCollectionDao;
    private final UserCollectionService userCollectionService;
    private final MerchantPledgeTaskCollectionConfDao merchantPledgeTaskCollectionConfDao;
    private final UserMerchantPledgeTaskCollectionRecordsDao userMerchantPledgeTaskCollectionRecordsDao;
    @Override
    public Page<MerchantPledgeTaskPageVO> getTaskPage(Long daoId,Integer pageNo, Integer pageSize) {
        return merchantPledgeTaskConfDao.getTaskPage(daoId,pageNo, pageSize);
    }

    @Override
    public GetTaskDetailsVO getTaskDetails(UserInfo user, Long id) {
        MerchantPledgeTaskConf pledgeTaskConf = checkMerchantPledgeTaskConf(id);
        //基础信息
        GetTaskDetailsVO getTaskDetailsVO = BeanUtil.copyProperties(pledgeTaskConf, GetTaskDetailsVO.class);
        getTaskDetailsVO.setBeginTimeStamp(pledgeTaskConf.getBeginTime().getTime());
        getTaskDetailsVO.setEndTimeStamp(pledgeTaskConf.getEndTime().getTime());
        getTaskDetailsVO.setNowTimeStamp(DateTime.now().getTime());

        //用户已经参数的有效记录数量
        Integer sumUserCount = userMerchantPledgeTaskRecordsDao.getSumPledgeCountByUserIdAndMerchantPledgeTaskIdAndStatus(user.getId(), pledgeTaskConf.getId());
        getTaskDetailsVO.setUserCount(pledgeTaskConf.getUserCount() - sumUserCount >=0? pledgeTaskConf.getUserCount() - sumUserCount : 0 );

        //获取已经质押的数量
        Integer pledgeCount = userMerchantPledgeTaskRecordsDao.getCountMerchantPledgeTaskId(pledgeTaskConf.getId());
        getTaskDetailsVO.setRemainingCount(pledgeTaskConf.getUpperLimit() - pledgeCount < 0 ? 0 : pledgeTaskConf.getUpperLimit() - pledgeCount);

        List<TaskDetailsCollectionConfVO> collectionConfList = Lists.newArrayList();
        //挖宝条件
        List<MerchantPledgeTaskCollectionConf> collectionConf = merchantPledgeTaskCollectionConfDao.getListByTaskConfId(pledgeTaskConf.getId());
        for (MerchantPledgeTaskCollectionConf merchantPledgeTaskCollectionConf : collectionConf) {
            TaskDetailsCollectionConfVO confCollectionVO = BeanUtil.copyProperties(merchantPledgeTaskCollectionConf, TaskDetailsCollectionConfVO.class);
            confCollectionVO.setHoldCount(userCollectionDao.getCountByCollectionId(merchantPledgeTaskCollectionConf.getCollectionId(),user.getId()));
            collectionConfList.add(confCollectionVO);
        }
        getTaskDetailsVO.setCollectionConfList(collectionConfList);

        List<PledgeTaskCycleConfDetailsVO> cycleDetailsList = Lists.newArrayList();
        //获取周期
        List<MerchantPledgeTaskCycleConf> pledgeTaskCycleList = merchantPledgeTaskCycleConfDao.getCycleListByPledgeTaskConfId(pledgeTaskConf.getId());
        for (MerchantPledgeTaskCycleConf merchantPledgeTaskCycleConf : pledgeTaskCycleList) {
            PledgeTaskCycleConfDetailsVO pledgeTaskCycleConfDetailsVO = BeanUtil.copyProperties(merchantPledgeTaskCycleConf, PledgeTaskCycleConfDetailsVO.class);
            pledgeTaskCycleConfDetailsVO.setCycleConfid(merchantPledgeTaskCycleConf.getId());

            pledgeTaskCycleConfDetailsVO.setRewardsCycle(pledgeTaskCycleConfDetailsVO.getRewardsCycle() == 0 ? 1 : pledgeTaskCycleConfDetailsVO.getRewardsCycle());
            Integer count = pledgeTaskCycleConfDetailsVO.getPledgeCycle() / pledgeTaskCycleConfDetailsVO.getRewardsCycle();
            pledgeTaskCycleConfDetailsVO.setRewardsCount(count == 0 ? 1 : count);

            List<MerchantPledgeTaskRewardsConf> list = merchantPledgeTaskRewardsConfDao.getListByCycleConfId(merchantPledgeTaskCycleConf.getId());
            pledgeTaskCycleConfDetailsVO.setCycleRewardsDetailslist(BeanUtil.copyToList(list, MerchantPledgeTaskCycleRewardsDetailsVO.class));
            cycleDetailsList.add(pledgeTaskCycleConfDetailsVO);
        }
        getTaskDetailsVO.setCycleDetailsList(cycleDetailsList);

        return getTaskDetailsVO;
    }

    @Override
    public Boolean isPledgeConditions(UserInfo user, Long merchantPledgeTaskId, Long cycleConfid, Integer count,List<PledeCollectionConfDTO> pledeCollectionList) {
        MerchantPledgeTaskConf pledgeTaskConf = checkMerchantPledgeTaskConf(merchantPledgeTaskId);
        //校验开始时间和结束时间
        DateTime now = DateTime.now();
        Assert.isFalse(now.isBefore(pledgeTaskConf.getBeginTime()),()->new GlobalRunTimeException("质押未到开启时间"));
        Assert.isFalse(now.after(pledgeTaskConf.getEndTime()),()->new GlobalRunTimeException("质押已经结束"));

        //获取指定周期
        MerchantPledgeTaskCycleConf cycleConf = merchantPledgeTaskCycleConfDao.getOneByIdAndMerchantPledgeTaskId(cycleConfid,merchantPledgeTaskId);
        Assert.notNull(cycleConf,()->new GlobalRunTimeException("该周期不存在"));
        List<MerchantPledgeTaskCollectionConf> collectionConfs = merchantPledgeTaskCollectionConfDao.getListByTaskConfId(pledgeTaskConf.getId());
        if(pledgeTaskConf.getType() == PledgeTaskTypeEnum.AND){
            for (MerchantPledgeTaskCollectionConf collectionConf : collectionConfs) {
                //单价*数量 = 总量
                Integer sumCount = collectionConf.getPledgeCount() * count;
                List<UserCollection> userCollectionList = userCollectionDao.getUserCollectionListByCollectionIdAndUserIdAndSize(collectionConf.getCollectionId(), user.getId(), sumCount);
                Assert.isFalse(userCollectionList.size() != sumCount,()->new GlobalRunTimeException(StrUtil.format("{}持有数量不满足条件",collectionConf.getCollectionName())));
            }
        }else if(pledgeTaskConf.getType() == PledgeTaskTypeEnum.OR){
            Assert.isFalse(pledeCollectionList.size() ==0,()->new GlobalRunTimeException("请选择质押藏品"));
            //判断传入的数量是否条件的整数倍
            int sum = pledeCollectionList.stream().mapToInt(o -> Objects.isNull(o.getCount()) ? 0 : o.getCount()).sum();
            count = Convert.toBigDecimal(sum).divide(Convert.toBigDecimal(pledgeTaskConf.getPledgeSumCount()), 2, BigDecimal.ROUND_DOWN).intValue();

            Assert.isTrue(sum % pledgeTaskConf.getPledgeSumCount() == 0,()->new GlobalRunTimeException("质押份数不正确"));
            for (PledeCollectionConfDTO pledeCollectionConfDTO : pledeCollectionList) {
                MerchantPledgeTaskCollectionConf collectionConf = merchantPledgeTaskCollectionConfDao.getListByTaskConfIdAndCollectionId(pledgeTaskConf.getId(),pledeCollectionConfDTO.getCollectionId());
                Assert.notNull(collectionConf,()->new GlobalRunTimeException("请选择正确质押藏品"));
                List<UserCollection> userCollectionList = userCollectionDao.getUserCollectionListByCollectionIdAndUserIdAndSize(pledeCollectionConfDTO.getCollectionId(), user.getId(), pledeCollectionConfDTO.getCount());
                Assert.isTrue(userCollectionList.size() == pledeCollectionConfDTO.getCount(),()->new GlobalRunTimeException(StrUtil.format("{}持有数量不满足条件",collectionConf.getCollectionName())));
            }
        }
        return Boolean.TRUE;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pledgeCollection(UserInfo user, MerchantPledgeTaskConf pledgeTaskConf, Long cycleConfid,Integer count,List<PledeCollectionConfDTO> pledeCollectionList) {
//        MerchantPledgeTaskConf pledgeTaskConf = checkMerchantPledgeTaskConf(merchantPledgeTaskId);


        Integer sumUserCount = userMerchantPledgeTaskRecordsDao.getSumPledgeCountByUserIdAndMerchantPledgeTaskIdAndStatus(user.getId(), pledgeTaskConf.getId());

        //校验开始时间和结束时间
        DateTime now = DateTime.now();
        Assert.isFalse(now.isBefore(pledgeTaskConf.getBeginTime()),()->new GlobalRunTimeException("质押未到开启时间"));
        Assert.isFalse(now.after(pledgeTaskConf.getEndTime()),()->new GlobalRunTimeException("质押已经结束"));

        //获取指定周期
        MerchantPledgeTaskCycleConf cycleConf = merchantPledgeTaskCycleConfDao.getOneByIdAndMerchantPledgeTaskId(cycleConfid,pledgeTaskConf.getId());
        Assert.notNull(cycleConf,()->new GlobalRunTimeException("该周期不存在"));


        List<UserCollection> allUserCollectionList = Lists.newArrayList();
        List<MerchantPledgeTaskCollectionConf> collectionConfs = merchantPledgeTaskCollectionConfDao.getListByTaskConfId(pledgeTaskConf.getId());
        Assert.isTrue(collectionConfs.size() > 0,()->new GlobalRunTimeException("该质押任务没有挖宝条件"));

        if(pledgeTaskConf.getType() == PledgeTaskTypeEnum.AND){
            for (MerchantPledgeTaskCollectionConf collectionConf : collectionConfs) {
                pledgeTaskConf.getUserCount();
                Assert.isTrue(sumUserCount + count <= pledgeTaskConf.getUserCount(),()->new GlobalRunTimeException("当前挖宝次数已达上限"));
                //单价*数量 = 总量
                Integer sumCount = collectionConf.getPledgeCount() * count;
                List<UserCollection> userCollectionList = userCollectionDao.getUserCollectionListByCollectionIdAndUserIdAndSize(collectionConf.getCollectionId(), user.getId(), sumCount);
                Assert.isFalse(userCollectionList.size() != sumCount.intValue(),()->new GlobalRunTimeException(StrUtil.format("{}持有数量不满足条件",collectionConf.getCollectionName())));
                allUserCollectionList.addAll(userCollectionList);
            }
        }else if (pledgeTaskConf.getType() == PledgeTaskTypeEnum.OR){
            Assert.isFalse(pledeCollectionList.size() ==0,()->new GlobalRunTimeException("请选择质押藏品"));
            //判断传入的数量是否条件的整数倍
            //判断传入的数量是否条件的整数倍
            int sum = pledeCollectionList.stream().mapToInt(o -> Objects.isNull(o.getCount()) ? 0 : o.getCount()).sum();
            count = Convert.toBigDecimal(sum).divide(Convert.toBigDecimal(pledgeTaskConf.getPledgeSumCount()), 2, BigDecimal.ROUND_DOWN).intValue();

            Assert.isTrue(sum % pledgeTaskConf.getPledgeSumCount() == 0,()->new GlobalRunTimeException("质押份数不正确"));
            Assert.isTrue(sumUserCount + count <= pledgeTaskConf.getUserCount(),()->new GlobalRunTimeException("当前挖宝次数已达个人上限"));

            for (PledeCollectionConfDTO pledeCollectionConfDTO : pledeCollectionList) {
                MerchantPledgeTaskCollectionConf collectionConf = merchantPledgeTaskCollectionConfDao.getListByTaskConfIdAndCollectionId(pledgeTaskConf.getId(),pledeCollectionConfDTO.getCollectionId());
                Assert.notNull(collectionConf,()->new GlobalRunTimeException("请选择正确质押藏品"));

                List<UserCollection> userCollectionList = userCollectionDao.getUserCollectionListByCollectionIdAndUserIdAndSize(pledeCollectionConfDTO.getCollectionId(), user.getId(), pledeCollectionConfDTO.getCount());
                Assert.isTrue(userCollectionList.size() == pledeCollectionConfDTO.getCount(),()->new GlobalRunTimeException(StrUtil.format("{}持有数量不满足条件",collectionConf.getCollectionName())));
                allUserCollectionList.addAll(userCollectionList);
            }
        }

        List<Long> userCollectionIds = allUserCollectionList.stream().map(UserCollection::getId).collect(Collectors.toList());
        //把藏品修改为质押状态
        Assert.isTrue(userCollectionDao.updateFreezingStatusByIds(userCollectionIds, UserCollectionFreezingStatusEnum.PRESSING),()->new GlobalRunTimeException("质押失败"));

        //添加质押记录
        UserMerchantPledgeTaskRecords userMerchantPledgeTaskRecords = new UserMerchantPledgeTaskRecords();
        userMerchantPledgeTaskRecords.setUserId(user.getId());
        userMerchantPledgeTaskRecords.setDaoId(pledgeTaskConf.getDaoId());
        userMerchantPledgeTaskRecords.setDaoName(pledgeTaskConf.getDaoName());
        userMerchantPledgeTaskRecords.setMerchantPledgeTaskId(pledgeTaskConf.getId());
        userMerchantPledgeTaskRecords.setMerchantPledgeTaskCycleConfId(cycleConf.getId());
        userMerchantPledgeTaskRecords.setPledgeCycle(cycleConf.getPledgeCycle());
        //质押份数
        userMerchantPledgeTaskRecords.setPledgeCount(count);
        userMerchantPledgeTaskRecords.setPledgeCollectionCount(allUserCollectionList.size());
        userMerchantPledgeTaskRecords.setRewardsCount(0);
        userMerchantPledgeTaskRecords.setSettleDay(0);

        Integer pledgeCount = userMerchantPledgeTaskRecordsDao.getCountMerchantPledgeTaskId(userMerchantPledgeTaskRecords.getMerchantPledgeTaskId());
        Assert.isFalse(pledgeCount + count > pledgeTaskConf.getUpperLimit(),()->new GlobalRunTimeException("活动太火爆了，敬请期待下一次活动"));
        userMerchantPledgeTaskRecords.setIsAuto(Boolean.FALSE);
        userMerchantPledgeTaskRecords.setStatus(UserMerchantPledgeTaskStatusEnum.NOT_YET_STARTED);

        DateTime endTime = DateUtil.offset(DateTime.now(), DateField.HOUR, (cycleConf.getPledgeCycle() + 1) * 24);
        endTime.setHours(0);
        endTime.setMinutes(0);
        endTime.setSeconds(0);
        userMerchantPledgeTaskRecords.setEndTime(endTime);

        DateTime exitTime = DateUtil.offset(DateTime.now(), DateField.HOUR, (cycleConf.getExitDay() + 1)* 24);
        exitTime.setHours(0);
        exitTime.setMinutes(0);
        exitTime.setSeconds(0);
        userMerchantPledgeTaskRecords.setExitTime(exitTime);

        List<MerchantPledgeTaskRewardsConf> cycleRewardsLst = merchantPledgeTaskRewardsConfDao.getListByCycleConfId(cycleConfid);
        String rewardsDetails = cycleRewardsLst.stream()
                .map(conf -> conf.getLinkName() + "*" + conf.getLinkCount())
                .collect(Collectors.joining(","));
        userMerchantPledgeTaskRecords.setRewardsDetails(rewardsDetails);
        userMerchantPledgeTaskRecords.insert();

        for (UserCollection userCollection : allUserCollectionList) {
            UserMerchantPledgeTaskCollectionRecords userMerchantPledgeTaskCollectionRecords = new UserMerchantPledgeTaskCollectionRecords();
            userMerchantPledgeTaskCollectionRecords.setUserId(user.getId());
            userMerchantPledgeTaskCollectionRecords.setUserRecordsId(userMerchantPledgeTaskRecords.getId());
            userMerchantPledgeTaskCollectionRecords.setCollectionId(userCollection.getCollectionId());
            userMerchantPledgeTaskCollectionRecords.setCollectionName(userCollection.getFirstTitle());
            userMerchantPledgeTaskCollectionRecords.setCollectionImage(userCollection.getCollectionImage());
            userMerchantPledgeTaskCollectionRecords.setNumbering(userCollection.getNumbering());
            userMerchantPledgeTaskCollectionRecords.setUserCollectionId(userCollection.getId());
            userMerchantPledgeTaskCollectionRecords.insert();
        }

    }

    @Override
    public Page<TreasureRecordPageVO> treasureRecordPage(UserInfo user, Integer pageNo, Integer pageSize) {
        Page<TreasureRecordPageVO> page = userMerchantPledgeTaskRecordsDao.treasureRecordPage(user.getId(), pageNo, pageSize);
        for (TreasureRecordPageVO record : page.getRecords()) {
            Date endTime = record.getEndTime();
            Long between = DateUtil.betweenDay(DateTime.now(), endTime, Boolean.FALSE);
            record.setRemainingDay(between.intValue() <=0 ? 0: between.intValue());
        }
        return page;
    }

    @Override
    public TreasureRecordDetailsVO treasureRecordDetails(UserInfo user, Long id) {
        TreasureRecordDetailsVO treasureRecordDetailsVO = userMerchantPledgeTaskRecordsDao.treasureRecordDetails(user.getId(), id);
        MerchantPledgeTaskSettlementRewardsLog merchantPledgeTaskSettlementRewardsLog = merchantPledgeTaskSettlementRewardsLogDao.getNextRewardsTimeByUserRecordsId(id);
        treasureRecordDetailsVO.setNextRewardsTime(ObjectUtil.isNull(merchantPledgeTaskSettlementRewardsLog) ? null : merchantPledgeTaskSettlementRewardsLog.getSettlementTime());
        treasureRecordDetailsVO.setRewardsList(userMerchantPledgeTaskDetailsRecordsDao.getListByUserRecordsId(user.getId(),id));

        Date endTime = treasureRecordDetailsVO.getEndTime();
        Long between = DateUtil.betweenDay(DateTime.now(), endTime, Boolean.FALSE);
        treasureRecordDetailsVO.setRemainingDay(between.intValue() <=0 ? 0: between.intValue());
        if(treasureRecordDetailsVO.getStatus() == UserMerchantPledgeTaskStatusEnum.ALREADY_ENDED || treasureRecordDetailsVO.getStatus() == UserMerchantPledgeTaskStatusEnum.COMPLETED){
            treasureRecordDetailsVO.setRemainingDay(0);
        }

        treasureRecordDetailsVO.setUserCollectionList(userMerchantPledgeTaskCollectionRecordsDao.getCollectionByUserRecordsIdGroupCollectionId(id,user.getId()));
        return treasureRecordDetailsVO;
    }

    @Override
    public Page<IncomeRecordPageVO> incomeRecordPage(UserInfo user, Integer pageNo, Integer pageSize) {
        return merchantPledgeTaskIncomeConfDao.incomeRecordPage(user.getId(),pageNo,pageSize);
    }

    @Override
    public List<MerchantPledgeCollectionRewardsVO> incomeRecordDetails(UserInfo user, Long id) {
        return userMerchantPledgeTaskDetailsRecordsDao.incomeRecordDetails(user.getId(), id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void exitTaskByUserRecorId(UserInfo user, Long id) {
        UserMerchantPledgeTaskRecords userMerchantPledgeTaskRecords = userMerchantPledgeTaskRecordsDao.getByUserIdAndId(user.getId(),id);
        Assert.notNull(userMerchantPledgeTaskRecords,()->new GlobalRunTimeException("该质押记录不存在"));

        Assert.isTrue(userMerchantPledgeTaskRecords.getIsAuto(),()->new GlobalRunTimeException("该质押记录不可退出"));
        Assert.isTrue(DateTime.now().isBefore(userMerchantPledgeTaskRecords.getExitTime()),()->new GlobalRunTimeException("该质押记录超出时限"));
        Assert.isFalse(userMerchantPledgeTaskRecords.getIsFrozen(),()->new GlobalRunTimeException("冻结中，无法退出挖宝"));
        if(userMerchantPledgeTaskRecords.getStatus() == UserMerchantPledgeTaskStatusEnum.ALREADY_ENDED || (userMerchantPledgeTaskRecords.getStatus() == UserMerchantPledgeTaskStatusEnum.COMPLETED)){
            throw new GlobalRunTimeException("只有未开始和质押中的订单可以退出");
        }
        //获取用户质押藏品
        List<UserMerchantPledgeTaskCollectionRecords> listByUserRecordsId = userMerchantPledgeTaskCollectionRecordsDao.getListByUserRecordsId(userMerchantPledgeTaskRecords.getId());
        List<Long> userCollectionIds = listByUserRecordsId.stream().map(UserMerchantPledgeTaskCollectionRecords::getUserCollectionId).collect(Collectors.toList());

        //批量释放用户藏品
        Assert.isTrue(userCollectionService.updateFreezingStatusByIds(userCollectionIds,UserCollectionFreezingStatusEnum.NORMAL),()->new GlobalRunTimeException("藏品释放失败,请稍后重试"));
        //修改状态
        Assert.isTrue(userMerchantPledgeTaskRecordsDao.updateStatusById(id,UserMerchantPledgeTaskStatusEnum.ALREADY_ENDED),()->new GlobalRunTimeException("退出失败,请稍后重试"));
        if(userMerchantPledgeTaskRecords.getStatus() == UserMerchantPledgeTaskStatusEnum.IN_PLEDGE){
            Assert.isTrue(merchantPledgeTaskSettlementRewardsLogDao.delByUserIdAndUserPledgeTaskRecordsId(user.getId(),userMerchantPledgeTaskRecords.getId()),()->new GlobalRunTimeException("退出失败,请稍后重试"));
            merchantPledgeTaskSettlementRewardsLogDao.delIncomeRecordsByUserIdAndUserPledgeTaskRecordsId(user.getId(),userMerchantPledgeTaskRecords.getId());
        }
    }


    private MerchantPledgeTaskConf checkMerchantPledgeTaskConf(Long merchantPledgeTaskId){
        MerchantPledgeTaskConf pledgeTaskConf = merchantPledgeTaskConfDao.getById(merchantPledgeTaskId);
        Assert.notNull(pledgeTaskConf,()->new GlobalRunTimeException("该质押任务不存在"));
        Assert.isTrue(pledgeTaskConf.getIsListing(),()->new GlobalRunTimeException("该质押任务已下架"));
        Assert.isTrue(pledgeTaskConf.getExamineStatus() == MerchantPledgeTaskExamineStatusEnum.AUDIT_SUCCESS,()->new GlobalRunTimeException("该质押任务已下架"));
        return pledgeTaskConf;
    }

}